limsAcqConfigManufacturer.editPage = {

    getGridParam : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-acq-config-manufacturer-edit-list-grid',
            url : limsAcqConfigManufacturer.baseUrl + '/queries',
            service : 'limsAcqConfigManufacturerServiceImpl',
            dbTable : 'T_LIMS_ACQ_CONFIG_MANUFACTURER',
            columns : limsAcqConfigManufacturer.getEditListColumns(),
            group: {
                groupCheckbox: false,
                fields: ['manufacturer'],
                formatter: function (row) {
                    return row.manufacturer;
                }
            },
            deleteFormatter : function(row) {
                return row.manufacturer || row.id;
            },
            onLoadSuccess: function (data) {
                 if (!Gikam.isEmpty(data)) {
                     this.activeRowByIndex(0);
                 } else {
                     Gikam.cleanCompData(['lims-acq-config-instlib-edit-list-grid']);
                 }
             },
             onRowActive: function (index, row) {
                 Gikam.getAsyncComp('lims-acq-config-instlib-edit-list-grid').done(function (grid) {
                     grid.refresh({
                         url: limsAcqConfigInstlib.baseUrl + '/queries',
                         requestData : {
                            manufacturerId_SEQ : row.id
                         }
                     });
                 });

                Gikam.getAsyncComp('attachuploader').done(function (comp) {
                     comp.setOptions({
                         bizId: row.id,
                     });
                 });

             },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    Gikam.preInsert({
                        modalTitle : 'BASEMODULE.COMMON.EPTSTORAGE.ACQCONFIGS.MODAL.ADD',
                        fields : limsAcqConfigManufacturer.getBaseInfoFormFields(),
                        url : limsAcqConfigManufacturer.baseUrl
                    }).done(function(id) {
                        Gikam.getComp('lims-acq-config-manufacturer-edit-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove-row',
                onClick : function() {
                    Gikam.getComp('lims-acq-config-manufacturer-edit-list-grid').deleteRows(limsAcqConfigManufacturer.baseUrl);
                }
            } ]
        }
    },

    getGridInstlibParam : function(){
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-acq-config-instlib-edit-list-grid',
            service : 'limsAcqConfigInstlibServiceImpl',
            dbTable : 'T_LIMS_ACQ_CONFIG_INSTLIB',
            columns : limsAcqConfigInstlib.getEditListColumns(),
            deleteFormatter : function(row) {
                return row.instructionName || row.id;
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    var gridmanufacturer = Gikam.getComp('lims-acq-config-manufacturer-edit-list-grid');
                    var activedRow = gridmanufacturer.getActivedRow();
                    if (Gikam.isEmpty(activedRow)) {
                        return ;
                    }
                    Gikam.preInsert({
                        modalTitle : 'BASEMODULE.COMMON.EPTSTORAGE.ACQCONFIGS.MODAL.ADD',
                        fields : limsAcqConfigInstlib.getBaseInfoFormFields(),
                        url : limsAcqConfigInstlib.baseUrl,
                        titleWidth : 100,
                        param : {
                            manufacturerId : activedRow.id
                        }
                    }).done(function(id) {
                        Gikam.getComp('lims-acq-config-instlib-edit-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove-row',
                onClick : function() {
                    Gikam.getComp('lims-acq-config-instlib-edit-list-grid').deleteRows(limsAcqConfigInstlib.baseUrl);
                }
            } ]
        }
    },


    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-acq-config-manufacturer-edit-list-layout',
            renderTo : workspace.window.$dom,
            center : {
                title : 'T_LIMS_ACQ_CONFIG_MANUFACTURER.SERVICE_NAME',
                items : [ this.getGridParam() ]
            },
            east : {
                 width : '60%',
                 items : [{
                    type : 'tab',
                    panels : [{
                        title : 'T_LIMS_ACQ_CONFIG_INSTLIB.SERVICE_NAME',
                        items : [this.getGridInstlibParam()]
                    },{
                        title : 'T_LIMS_ACQ_CONFIG_INSTLIB.ATTACH',
                        items : [{
                             type: 'uploader',
                             id: 'attachuploader',
                             dbTable: 'T_LIMS_ACQ_CONFIG_MANUFACTURER',
                     }]
                 }]}]
            },
        });
    },

    init : function() {
        this.create();
    }
};
